#!/usr/bin/env node

const axios = require('axios')
const { RunCmd, CmdList } = require('./lib/core/cmd')
const { Inquirer } = require('./lib/core/inquirer')
// 询问用户输入仓库信息
Inquirer().then(({ name, description, private }) => {
  // 获取Gitee API Token
  // 发送创建仓库请求
  axios({
    method: 'post',
    url: 'https://gitee.com/api/v5/user/repos',
    headers: {
      Authorization: `Bearer 3041c87a0f5727c36b997af93cb3549b`
    },
    data: {
      name,
      description,
      private
    }
  })
    .then(({ data }) => {
      console.log(`成功创建仓库：${data.html_url}`)
      console.log(`正在上传代码~`)
      for (let cmd of CmdList(data.full_name)) {
        RunCmd(cmd)
      }
      console.log(`上传完成~`)
    })
    .catch((err) => {
      console.error(`创建仓库失败：${err.message}`)
    })
})
